#-*- mode: shell-script;-*-

# Debian GNU/Linux dput(1) completion
# Copyright 2002 Roland Mas <lolando@debian.org>

have dput &&
_dput()
{
    local cur prev options paroptions special i delayed_options hosts
    
    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}
    options='-c --config -d --debug -D --dinstall -f --force -h --help \
             -H --host-list -l --lintian -o --check-only -p --print \
             -P --passive -s --simulate -u --unchecked -e --delayed \
             -v --version -V --check-version'

    hosts=$(
	{
	    grep "^\[.*\]" $HOME/.dput.cf 2> /dev/null | tr -d [] || /bin/true
	    grep "^\[.*\]" /etc/dput.cf 2> /dev/null | tr -d [] || /bin/true
	} | grep -v '^DEFAULT$' | sort -u)

    paroptions="$options $hosts"

    case $prev in
	--delayed|-e)
	    delayed_options='0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15'
	    COMPREPLY=( $( compgen -W "$delayed_options" | grep ^$cur ) )
	    ;;
	--config|-c)
	    COMPREPLY=( $( compgen -o filenames -G "$cur*" ) )
	    ;;
	*)
	    COMPREPLY=( $(
		    compgen -G "${cur}*.changes"
		    compgen -G "${cur}*.asc"
		    compgen -G "${cur}*.sig"
		    compgen -W "$paroptions" | grep "^$cur"
		) )
	    ;;
    esac

    return 0

}
[ "$have" ] && complete -F _dput -o filenames -o plusdirs dput
